package com.yjj.demo.id.generator.service;

import com.yjj.demo.id.generator.dao.IdGeneratorDao;
import com.yjj.demo.id.generator.entity.IdGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * id生成器
 *
 * @author yangjiajia
 * @time 2021/6/6 21:50
 */
@Service("defaultIdGeneratorService")
public class DefaultGeneratorService implements IIdGeneratorService {

    private Logger logger = LoggerFactory.getLogger(DefaultGeneratorService.class);

    @Autowired
    private IdGeneratorDao idGeneratorDao;

    @Override
    public long nextId(String module) {
        IdGenerator idGenerator = idGeneratorDao.nextId(module);
        long nextId = idGenerator.getCurrentId();
        logger.info("module:{},nextId:{}", module, nextId);
        return nextId;
    }

}
